VERSION 5.00
Begin VB.Form frm_permisos 
   BackColor       =   &H00C0FFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "ABM Permisos"
   ClientHeight    =   6300
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8850
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   420
   ScaleMode       =   3  'Pixel
   ScaleWidth      =   590
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame1 
      BackColor       =   &H00C0FFFF&
      Height          =   4215
      Left            =   240
      TabIndex        =   8
      Top             =   1800
      Width           =   5775
      Begin VB.ListBox lst_formularios 
         Height          =   3435
         Left            =   480
         Style           =   1  'Checkbox
         TabIndex        =   4
         Top             =   480
         Width           =   4815
      End
   End
   Begin VB.Frame Frame3 
      BackColor       =   &H00C0FFFF&
      Height          =   3495
      Left            =   6240
      TabIndex        =   6
      Top             =   600
      Width           =   2295
      Begin VB.CommandButton cmd_exportar 
         Caption         =   "&Exportar"
         Height          =   550
         Left            =   480
         TabIndex        =   3
         Top             =   2520
         Width           =   1335
      End
      Begin VB.CommandButton cmd_listar 
         Caption         =   "&Listar"
         Height          =   550
         Left            =   480
         TabIndex        =   2
         Top             =   1800
         Width           =   1335
      End
      Begin VB.CommandButton cmd_cancelar 
         Caption         =   "&Cancelar"
         Height          =   550
         Left            =   480
         TabIndex        =   1
         Top             =   1080
         Width           =   1335
      End
      Begin VB.CommandButton cmd_guardar 
         Caption         =   "&Guardar"
         Height          =   550
         Left            =   480
         TabIndex        =   0
         Top             =   360
         Width           =   1335
      End
   End
   Begin VB.Frame fra_datos 
      BackColor       =   &H00C0FFFF&
      Height          =   1095
      Left            =   240
      TabIndex        =   5
      Top             =   600
      Width           =   5775
      Begin VB.ComboBox cbo_roles 
         Height          =   315
         Left            =   960
         Style           =   2  'Dropdown List
         TabIndex        =   9
         Top             =   360
         Width           =   4215
      End
      Begin VB.Label Label9 
         BackColor       =   &H00C0FFFF&
         Caption         =   "Rol:"
         ForeColor       =   &H00000000&
         Height          =   330
         Left            =   240
         TabIndex        =   7
         Top             =   360
         Width           =   1215
      End
   End
End
Attribute VB_Name = "frm_permisos"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim rs As New ADODB.Recordset




Private Sub cbo_roles_Click()

lst_formularios.Clear

'Dim us As New ADODB.Recordset
'fijarme como es la consulta la parte de la concatenacion
'us.Open "select cod_usuario from t_usuario where  cod_usuario = " & cbo_usuarios.ItemData(cbo_usuarios.ListIndex) & "", con, adOpenForwardOnly, adLockReadOnly, adCmdText

Dim rs2 As New ADODB.Recordset
rs2.Open "select titulo_formulario from t_formulario", con, adOpenForwardOnly, adLockReadOnly, adCmdText

rs2.MoveFirst
Dim i As Integer
For i = 1 To rs2.RecordCount
    lst_formularios.AddItem (rs2!titulo_formulario)
    rs2.MoveNext
    
Next i


Dim rs3 As New ADODB.Recordset
Dim j As Integer
rs3.Open " select t_formulario.titulo_formulario from t_rolxformulario inner join t_formulario on t_rolxformulario.cod_formulario = t_formulario.cod_formulario where t_rolxformulario.cod_rol = " & cbo_roles.ItemData(cbo_roles.ListIndex) & "", con, adOpenForwardOnly, adLockReadOnly, adCmdText
 

Dim z As Integer

If rs3.RecordCount > 0 Then

rs3.MoveFirst

For z = 1 To rs3.RecordCount

 For j = 0 To lst_formularios.ListCount - 1
  
     If lst_formularios.List(j) = rs3(0) Then
    
       lst_formularios.Selected(j) = True
       
       Exit For
        
        
     End If
     
          
    Next j
   rs3.MoveNext
 Next z
 
 
 
 
 
 End If

    'if cod_formulario = lst_formularios.ItemData(
    'if los nombres coinciden tildar el renglon de la lista
        'lst_usuario.ListIndex(j) rs!titulo_formulario
       'mover el rst2
    'end if

End Sub

Private Sub cmd_cancelar_Click()

lst_formularios.Clear

cbo_roles.Clear

cbo_roles.SetFocus

End Sub

Private Sub cmd_guardar_Click()

Dim rs4 As New ADODB.Recordset
Dim rs5 As New ADODB.Recordset
Dim w As Integer

con.Execute "delete from t_rolxformulario where cod_rol =" & cbo_roles.ItemData(cbo_roles.ListIndex) & ""
    

rs4.Open " select cod_formulario, titulo_formulario from t_formulario", con, adOpenForwardOnly, adLockReadOnly, adCmdText
rs5.Open " select * from t_rolxformulario ", con, adOpenDynamic, adLockOptimistic, adCmdText
 
For w = 0 To lst_formularios.ListCount - 1

 If lst_formularios.Selected(w) = True Then
 
  rs4.Filter = " titulo_formulario = '" & lst_formularios.List(w) & "' "
         
  Dim codigo As Integer
  
  codigo = rs4(0)
  
  rs5.AddNew
  
  rs5!cod_formulario = rs4!cod_formulario
  
  rs5!cod_rol = cbo_roles.ItemData(cbo_roles.ListIndex)
  
  rs5.Update

   End If

  
 Next w
 
 MsgBox "Los cambios han sido guardados", vbExclamation, "Mensaje"
 
End Sub

Private Sub Form_Load()
    Set colorFondo = Me
    
    Call cargar_cbo("Rol", cbo_roles)
End Sub


Private Sub cargar_cbo(Rol As String, cbo As ComboBox)
    Dim rs As New ADODB.Recordset
    
        
   rs.Open "select cod_rol, dsc_rol from t_rol Where fec_baja is null", con, adOpenForwardOnly, adLockReadOnly, adCmdText
       
    
    Call Actualiza_RS(rs)
    
    If rs.RecordCount = 0 Then
        Set rs = Nothing
        Exit Sub
    End If
    
    cbo.Clear
    
    Do While rs.EOF = False
        cbo.AddItem rs(1)
        cbo.ItemData(cbo.NewIndex) = rs(0)

        rs.MoveNext
    Loop
    Set rs = Nothing
End Sub






